import tensorflow as tf
from sklearn import datasets
import numpy as np

x_train,y_train =  datasets.load_iris().data,datasets.load_iris().target#加载训练数据与标签

#打乱训练数据
np.random.seed(116)
np.random.shuffle(x_train)
np.random.seed(116)
np.random.shuffle(y_train)

model = tf.keras.models.Sequential([tf.keras.layers.Flatten(),
									tf.keras.layers.Dense(3,activation = 'sigmoid')])

model.compile(optimizer = 'adam',loss = 'sparse_categorical_crossentropy',metrics = ['sparse_categorical_accuracy'])

model.fit(x_train,y_train,batch_size=32,epochs = 500,validation_freq = 25,validation_split=0.2)

model.summary()